﻿using System.Net;
using System.Net.Http;

namespace OkFlurl
{
    public class FlurlStreamContent : HttpContent
    {
        private readonly Func<Stream, Task> _onSend;

        public FlurlStreamContent(Func<Stream, Task> onSend)
        {
            _onSend = onSend;
        }

        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            await _onSend(stream);
        }

        protected override bool TryComputeLength(out long length)
        {
            length = -1;
            return false;
        }
    }
}
